package osx.mantianx.wirte;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;

/**
 * @author starrysky
 * @title: PoiExcel02
 * @projectName Excel_Poi_EasyExcel
 * @description: TODO
 * @date 2021/2/409:26
 */
public class PoiExcel02 {
    public static void main(String[] args) {
        //xlsx版 07  行数无限
        Workbook workbook = new XSSFWorkbook();
        //一个分表
        Sheet sheet = workbook.createSheet("学生在线统计表");
//        第一行
        Row row1 = sheet.createRow(0);
        Cell cell1 = row1.createCell(0);
        Cell cell2 = row1.createCell(1);
//        第二行
        Row row2 = sheet.createRow(1);
        Cell cell3 = row2.createCell(0);
        Cell cell4 = row2.createCell(1);

        cell1.setCellValue("姓名");
        cell2.setCellValue("学号");
        cell3.setCellValue("张楠");
        cell4.setCellValue("201920201590088");

        FileOutputStream fileOutputStream =null;
        try {
            fileOutputStream = new FileOutputStream("excel-"+ UUID.randomUUID() +".xlsx");
            workbook.write(fileOutputStream);
            System.out.println("文档生成完毕");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileOutputStream!=null){
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
